#!/bin/bash

set -e

export GO111MODULE=on

upstream=github.com/google/zoekt
fork=github.com/sourcegraph/zoekt

module="$(go get ${fork}@master 2>&1 | grep -E -o ${fork}'@v0.0.0-[0-9a-z-]+')"

go mod edit "-replace=${upstream}=${module}"
go mod download ${upstream}

# Ensure we update go.sum by actually compiling some code which depends on
# zoekt
go test -run '^$' github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend
